import { Component, OnInit } from '@angular/core';
import {LocalDataSource} from "ng2-smart-table";
import {AccountService} from "../../share/services/account.service";
import {DatetimeRenderComponent} from "../../share/components/grid-related/datetime-render/datetime-render.component";

@Component({
  selector: 'app-account',
  templateUrl: './account.component.html',
  styleUrls: ['./account.component.css']
})
export class AccountComponent implements OnInit {
  settings
  source: LocalDataSource;
  constructor(private accountService: AccountService) {
    this.source = new LocalDataSource();
  }

  ngOnInit() {
    console.debug('AccountComponent init')
    this.settings = {
      selectMode: 'multi',
      hideSubHeader: true,
      noDataMessage: '没有数据',
      editable: false,
      attr: {
        class: 'table table-striped table-bordered'
      },
      rowClassFunction: this.rowClassFunction,
      actions: {
        columnTitle: '操作',
        add: false,
        edit: false,
        delete: true,
        position: 'right',
      },
      delete: {
        deleteButtonContent: '删除',
        confirmDelete: true,
      },
      page: {
        display: true,
        perPage: 10,
      },
      columns: {
        username: {
          title: '用户名',
        },
        departmentName: {
          title: '归属部门',
        },
        fullName: {
          title: '姓名',
        },
        tel: {
          title: '电话',
        },
        mobile: {
          title: '手机',
        },
        createDate: {
          title: '创建时间',
          type: 'custom',
          renderComponent: DatetimeRenderComponent,
        },
        status: {
          title: '状态',
        },
      }
    }
    this.loadData()
  }
  loadData(){
    this.accountService.list().subscribe(
      data => {
        this.source.load(data)
      }
    )
  }
  rowClassFunction(){
    return "list-table-row"
  }
  userRowSelect($event){
    console.debug($event)
  }
  mouseover($event){
    console.debug($event)
  }

}
